package com.dommettj.rawfix.utils;

import com.dommettj.rawfix.settings.FileProvider;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

public class StubFileProvider implements FileProvider {

    final List<File> files = new ArrayList<File>();

    @Override
    public File getFileForReading(final String filename) {
        return getFile(filename);
    }

    @Override
    public File getFileForWriting(final String filename) {
        return getFile(filename);
    }

    private File getFile(final String filename) {
        final File file = new File(filename);
        files.add(file);
        return file;
    }

    public void createPropertiesFile(final Properties properties, final String filename) throws IOException {

        final File file = new File(filename);
        properties.store(new FileOutputStream(file), null);
    }

    public void cleanupFiles() {

        for(File f : files) {
            f.delete();
        }
    }
}
